﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace CustomsSystem.DAL
{
    /// <summary>
    /// 数据访问类:T_plan
    /// </summary>
    public partial class planService
    {
        public planService()
        { }
        #region  BasicMethod

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return DbHelperSQL.GetMaxID("planID", "T_plan");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int planID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from T_plan");
            strSql.Append(" where planID=@planID");
            SqlParameter[] parameters = {
					new SqlParameter("@planID", SqlDbType.Int,4)
			};
            parameters[0].Value = planID;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(CustomsSystem.Model.T_plan model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_plan(");
            strSql.Append("typeID,inOut,cID,goodsType,tradeType,agencyDate,declaratoryDate,shipName,goodsName,No,grossWeight,goodsValue,Currency,customsNo,inspectionNo,clearanceNo,contractNo,agency,shipCompany,remark,warehouseNo1,warehouseNo2,warehouseNo3,agencyNo,ladingBillNo,verificationSheetNo,containerNo,headLadingBillNo,clearanceDate,transferNo1,transferNo2,transferNo3,filingNo,invTilte,inspetionAgancy,portFee,Checkfee,Destination,PO,inputEmpNo,inputDate,busIDbg,busIDbj,busNamebg,busNamebj,jobNobg,jobNobj,jobEmpNobg,jobEmpNobj,infoWKIDbg,infoWKIDbj,InfoWKTypeIDbg,InfoWKTypeIDbj,BatchNO,TestItem,Model,RegisterUnit,DangerousGoods,Transport)");
            strSql.Append(" values (");
            strSql.Append("@typeID,@inOut,@cID,@goodsType,@tradeType,@agencyDate,@declaratoryDate,@shipName,@goodsName,@No,@grossWeight,@goodsValue,@Currency,@customsNo,@inspectionNo,@clearanceNo,@contractNo,@agency,@shipCompany,@remark,@warehouseNo1,@warehouseNo2,@warehouseNo3,@agencyNo,@ladingBillNo,@verificationSheetNo,@containerNo,@headLadingBillNo,@clearanceDate,@transferNo1,@transferNo2,@transferNo3,@filingNo,@invTilte,@inspetionAgancy,@portFee,@Checkfee,@Destination,@PO,@inputEmpNo,@inputDate,@busIDbg,@busIDbj,@busNamebg,@busNamebj,@jobNobg,@jobNobj,@jobEmpNobg,@jobEmpNobj,@infoWKIDbg,@infoWKIDbj,@InfoWKTypeIDbg,@InfoWKTypeIDbj,@BatchNO,@TestItem,@Model,@RegisterUnit,@DangerousGoods,@Transport)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@typeID", SqlDbType.Int,4),
					new SqlParameter("@inOut", SqlDbType.Int,4),
					new SqlParameter("@cID", SqlDbType.Int,4),
					new SqlParameter("@goodsType", SqlDbType.Int,4),
					new SqlParameter("@tradeType", SqlDbType.Int,4),
					new SqlParameter("@agencyDate", SqlDbType.DateTime),
					new SqlParameter("@declaratoryDate", SqlDbType.DateTime),
					new SqlParameter("@shipName", SqlDbType.VarChar,60),
					new SqlParameter("@goodsName", SqlDbType.VarChar,60),
					new SqlParameter("@No", SqlDbType.VarChar,80),
					new SqlParameter("@grossWeight", SqlDbType.Decimal,13),
					new SqlParameter("@goodsValue", SqlDbType.Decimal,13),
					new SqlParameter("@Currency", SqlDbType.VarChar,30),
					new SqlParameter("@customsNo", SqlDbType.VarChar,500),
					new SqlParameter("@inspectionNo", SqlDbType.VarChar,30),
					new SqlParameter("@clearanceNo", SqlDbType.VarChar,60),
					new SqlParameter("@contractNo", SqlDbType.VarChar,50),
					new SqlParameter("@agency", SqlDbType.VarChar,50),
					new SqlParameter("@shipCompany", SqlDbType.VarChar,50),
					new SqlParameter("@remark", SqlDbType.VarChar,500),
					new SqlParameter("@warehouseNo1", SqlDbType.VarChar,50),
					new SqlParameter("@warehouseNo2", SqlDbType.VarChar,50),
					new SqlParameter("@warehouseNo3", SqlDbType.VarChar,50),
					new SqlParameter("@agencyNo", SqlDbType.VarChar,200),
					new SqlParameter("@ladingBillNo", SqlDbType.VarChar,50),
					new SqlParameter("@verificationSheetNo", SqlDbType.VarChar,50),
					new SqlParameter("@containerNo", SqlDbType.VarChar,2000),
					new SqlParameter("@headLadingBillNo", SqlDbType.VarChar,50),
					new SqlParameter("@clearanceDate", SqlDbType.DateTime),
					new SqlParameter("@transferNo1", SqlDbType.VarChar,50),
					new SqlParameter("@transferNo2", SqlDbType.VarChar,50),
					new SqlParameter("@transferNo3", SqlDbType.VarChar,50),
					new SqlParameter("@filingNo", SqlDbType.VarChar,50),
					new SqlParameter("@invTilte", SqlDbType.VarChar,100),
					new SqlParameter("@inspetionAgancy", SqlDbType.VarChar,100),
					new SqlParameter("@portFee", SqlDbType.Decimal,13),
					new SqlParameter("@Checkfee", SqlDbType.Decimal,13),
					new SqlParameter("@Destination", SqlDbType.VarChar,500),
					new SqlParameter("@PO", SqlDbType.VarChar,50),
					new SqlParameter("@inputEmpNo", SqlDbType.Char,4),
					new SqlParameter("@inputDate", SqlDbType.DateTime),
					new SqlParameter("@busIDbg", SqlDbType.Int,4),
					new SqlParameter("@busIDbj", SqlDbType.Int,4),
					new SqlParameter("@busNamebg", SqlDbType.VarChar,60),
					new SqlParameter("@busNamebj", SqlDbType.VarChar,60),
					new SqlParameter("@jobNobg", SqlDbType.VarChar,10),
					new SqlParameter("@jobNobj", SqlDbType.VarChar,10),
					new SqlParameter("@jobEmpNobg", SqlDbType.Char,4),
					new SqlParameter("@jobEmpNobj", SqlDbType.Char,4),
					new SqlParameter("@infoWKIDbg", SqlDbType.Int,4),
					new SqlParameter("@infoWKIDbj", SqlDbType.Int,4),
					new SqlParameter("@InfoWKTypeIDbg", SqlDbType.Int,4),
					new SqlParameter("@InfoWKTypeIDbj", SqlDbType.Int,4),
					new SqlParameter("@BatchNO", SqlDbType.VarChar,50),
					new SqlParameter("@TestItem", SqlDbType.VarChar,200),
					new SqlParameter("@Model", SqlDbType.VarChar,200),
					new SqlParameter("@RegisterUnit", SqlDbType.VarChar,200),
					new SqlParameter("@DangerousGoods", SqlDbType.Bit,1),
					new SqlParameter("@Transport", SqlDbType.VarChar,200)};
            parameters[0].Value = model.typeID;
            parameters[1].Value = model.inOut;
            parameters[2].Value = model.cID;
            parameters[3].Value = model.goodsType;
            parameters[4].Value = model.tradeType;
            parameters[5].Value = model.agencyDate;
            parameters[6].Value = model.declaratoryDate;
            parameters[7].Value = model.shipName;
            parameters[8].Value = model.goodsName;
            parameters[9].Value = model.No;
            parameters[10].Value = model.grossWeight;
            parameters[11].Value = model.goodsValue;
            parameters[12].Value = model.Currency;
            parameters[13].Value = model.customsNo;
            parameters[14].Value = model.inspectionNo;
            parameters[15].Value = model.clearanceNo;
            parameters[16].Value = model.contractNo;
            parameters[17].Value = model.agency;
            parameters[18].Value = model.shipCompany;
            parameters[19].Value = model.remark;
            parameters[20].Value = model.warehouseNo1;
            parameters[21].Value = model.warehouseNo2;
            parameters[22].Value = model.warehouseNo3;
            parameters[23].Value = model.agencyNo;
            parameters[24].Value = model.ladingBillNo;
            parameters[25].Value = model.verificationSheetNo;
            parameters[26].Value = model.containerNo;
            parameters[27].Value = model.headLadingBillNo;
            parameters[28].Value = model.clearanceDate;
            parameters[29].Value = model.transferNo1;
            parameters[30].Value = model.transferNo2;
            parameters[31].Value = model.transferNo3;
            parameters[32].Value = model.filingNo;
            parameters[33].Value = model.invTilte;
            parameters[34].Value = model.inspetionAgancy;
            parameters[35].Value = model.portFee;
            parameters[36].Value = model.Checkfee;
            parameters[37].Value = model.Destination;
            parameters[38].Value = model.PO;
            parameters[39].Value = model.inputEmpNo;
            parameters[40].Value = model.inputDate;
            parameters[41].Value = model.busIDbg;
            parameters[42].Value = model.busIDbj;
            parameters[43].Value = model.busNamebg;
            parameters[44].Value = model.busNamebj;
            parameters[45].Value = model.jobNobg;
            parameters[46].Value = model.jobNobj;
            parameters[47].Value = model.jobEmpNobg;
            parameters[48].Value = model.jobEmpNobj;
            parameters[49].Value = model.infoWKIDbg;
            parameters[50].Value = model.infoWKIDbj;
            parameters[51].Value = model.InfoWKTypeIDbg;
            parameters[52].Value = model.InfoWKTypeIDbj;
            parameters[53].Value = model.BatchNO;
            parameters[54].Value = model.TestItem;
            parameters[55].Value = model.Model;
            parameters[56].Value = model.RegisterUnit;
            parameters[57].Value = model.DangerousGoods;
            parameters[58].Value = model.Transport;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(CustomsSystem.Model.T_plan model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_plan set ");
            strSql.Append("typeID=@typeID,");
            strSql.Append("inOut=@inOut,");
            strSql.Append("cID=@cID,");
            strSql.Append("goodsType=@goodsType,");
            strSql.Append("tradeType=@tradeType,");
            strSql.Append("agencyDate=@agencyDate,");
            strSql.Append("declaratoryDate=@declaratoryDate,");
            strSql.Append("shipName=@shipName,");
            strSql.Append("goodsName=@goodsName,");
            strSql.Append("No=@No,");
            strSql.Append("grossWeight=@grossWeight,");
            strSql.Append("goodsValue=@goodsValue,");
            strSql.Append("Currency=@Currency,");
            strSql.Append("customsNo=@customsNo,");
            strSql.Append("inspectionNo=@inspectionNo,");
            strSql.Append("clearanceNo=@clearanceNo,");
            strSql.Append("contractNo=@contractNo,");
            strSql.Append("agency=@agency,");
            strSql.Append("shipCompany=@shipCompany,");
            strSql.Append("remark=@remark,");
            strSql.Append("warehouseNo1=@warehouseNo1,");
            strSql.Append("warehouseNo2=@warehouseNo2,");
            strSql.Append("warehouseNo3=@warehouseNo3,");
            strSql.Append("agencyNo=@agencyNo,");
            strSql.Append("ladingBillNo=@ladingBillNo,");
            strSql.Append("verificationSheetNo=@verificationSheetNo,");
            strSql.Append("containerNo=@containerNo,");
            strSql.Append("headLadingBillNo=@headLadingBillNo,");
            strSql.Append("clearanceDate=@clearanceDate,");
            strSql.Append("transferNo1=@transferNo1,");
            strSql.Append("transferNo2=@transferNo2,");
            strSql.Append("transferNo3=@transferNo3,");
            strSql.Append("filingNo=@filingNo,");
            strSql.Append("invTilte=@invTilte,");
            strSql.Append("inspetionAgancy=@inspetionAgancy,");
            strSql.Append("portFee=@portFee,");
            strSql.Append("Checkfee=@Checkfee,");
            strSql.Append("Destination=@Destination,");
            strSql.Append("PO=@PO,");
            strSql.Append("inputEmpNo=@inputEmpNo,");
            strSql.Append("inputDate=@inputDate,");
            strSql.Append("busIDbg=@busIDbg,");
            strSql.Append("busIDbj=@busIDbj,");
            strSql.Append("busNamebg=@busNamebg,");
            strSql.Append("busNamebj=@busNamebj,");
            strSql.Append("jobNobg=@jobNobg,");
            strSql.Append("jobNobj=@jobNobj,");
            strSql.Append("jobEmpNobg=@jobEmpNobg,");
            strSql.Append("jobEmpNobj=@jobEmpNobj,");
            strSql.Append("infoWKIDbg=@infoWKIDbg,");
            strSql.Append("infoWKIDbj=@infoWKIDbj,");
            strSql.Append("InfoWKTypeIDbg=@InfoWKTypeIDbg,");
            strSql.Append("InfoWKTypeIDbj=@InfoWKTypeIDbj,");
            strSql.Append("BatchNO=@BatchNO,");
            strSql.Append("TestItem=@TestItem,");
            strSql.Append("Model=@Model,");
            strSql.Append("RegisterUnit=@RegisterUnit,");
            strSql.Append("DangerousGoods=@DangerousGoods,");
            strSql.Append("Transport=@Transport");
            strSql.Append(" where planID=@planID");
            SqlParameter[] parameters = {
					new SqlParameter("@typeID", SqlDbType.Int,4),
					new SqlParameter("@inOut", SqlDbType.Int,4),
					new SqlParameter("@cID", SqlDbType.Int,4),
					new SqlParameter("@goodsType", SqlDbType.Int,4),
					new SqlParameter("@tradeType", SqlDbType.Int,4),
					new SqlParameter("@agencyDate", SqlDbType.DateTime),
					new SqlParameter("@declaratoryDate", SqlDbType.DateTime),
					new SqlParameter("@shipName", SqlDbType.VarChar,60),
					new SqlParameter("@goodsName", SqlDbType.VarChar,60),
					new SqlParameter("@No", SqlDbType.VarChar,80),
					new SqlParameter("@grossWeight", SqlDbType.Decimal,13),
					new SqlParameter("@goodsValue", SqlDbType.Decimal,13),
					new SqlParameter("@Currency", SqlDbType.VarChar,30),
					new SqlParameter("@customsNo", SqlDbType.VarChar,500),
					new SqlParameter("@inspectionNo", SqlDbType.VarChar,30),
					new SqlParameter("@clearanceNo", SqlDbType.VarChar,60),
					new SqlParameter("@contractNo", SqlDbType.VarChar,50),
					new SqlParameter("@agency", SqlDbType.VarChar,50),
					new SqlParameter("@shipCompany", SqlDbType.VarChar,50),
					new SqlParameter("@remark", SqlDbType.VarChar,500),
					new SqlParameter("@warehouseNo1", SqlDbType.VarChar,50),
					new SqlParameter("@warehouseNo2", SqlDbType.VarChar,50),
					new SqlParameter("@warehouseNo3", SqlDbType.VarChar,50),
					new SqlParameter("@agencyNo", SqlDbType.VarChar,200),
					new SqlParameter("@ladingBillNo", SqlDbType.VarChar,50),
					new SqlParameter("@verificationSheetNo", SqlDbType.VarChar,50),
					new SqlParameter("@containerNo", SqlDbType.VarChar,2000),
					new SqlParameter("@headLadingBillNo", SqlDbType.VarChar,50),
					new SqlParameter("@clearanceDate", SqlDbType.DateTime),
					new SqlParameter("@transferNo1", SqlDbType.VarChar,50),
					new SqlParameter("@transferNo2", SqlDbType.VarChar,50),
					new SqlParameter("@transferNo3", SqlDbType.VarChar,50),
					new SqlParameter("@filingNo", SqlDbType.VarChar,50),
					new SqlParameter("@invTilte", SqlDbType.VarChar,100),
					new SqlParameter("@inspetionAgancy", SqlDbType.VarChar,100),
					new SqlParameter("@portFee", SqlDbType.Decimal,13),
					new SqlParameter("@Checkfee", SqlDbType.Decimal,13),
					new SqlParameter("@Destination", SqlDbType.VarChar,500),
					new SqlParameter("@PO", SqlDbType.VarChar,50),
					new SqlParameter("@inputEmpNo", SqlDbType.Char,4),
					new SqlParameter("@inputDate", SqlDbType.DateTime),
					new SqlParameter("@busIDbg", SqlDbType.Int,4),
					new SqlParameter("@busIDbj", SqlDbType.Int,4),
					new SqlParameter("@busNamebg", SqlDbType.VarChar,60),
					new SqlParameter("@busNamebj", SqlDbType.VarChar,60),
					new SqlParameter("@jobNobg", SqlDbType.VarChar,10),
					new SqlParameter("@jobNobj", SqlDbType.VarChar,10),
					new SqlParameter("@jobEmpNobg", SqlDbType.Char,4),
					new SqlParameter("@jobEmpNobj", SqlDbType.Char,4),
					new SqlParameter("@infoWKIDbg", SqlDbType.Int,4),
					new SqlParameter("@infoWKIDbj", SqlDbType.Int,4),
					new SqlParameter("@InfoWKTypeIDbg", SqlDbType.Int,4),
					new SqlParameter("@InfoWKTypeIDbj", SqlDbType.Int,4),
					new SqlParameter("@BatchNO", SqlDbType.VarChar,50),
					new SqlParameter("@TestItem", SqlDbType.VarChar,200),
					new SqlParameter("@Model", SqlDbType.VarChar,200),
					new SqlParameter("@RegisterUnit", SqlDbType.VarChar,200),
					new SqlParameter("@DangerousGoods", SqlDbType.Bit,1),
					new SqlParameter("@Transport", SqlDbType.VarChar,200),
					new SqlParameter("@planID", SqlDbType.Int,4)};
            parameters[0].Value = model.typeID;
            parameters[1].Value = model.inOut;
            parameters[2].Value = model.cID;
            parameters[3].Value = model.goodsType;
            parameters[4].Value = model.tradeType;
            parameters[5].Value = model.agencyDate;
            parameters[6].Value = model.declaratoryDate;
            parameters[7].Value = model.shipName;
            parameters[8].Value = model.goodsName;
            parameters[9].Value = model.No;
            parameters[10].Value = model.grossWeight;
            parameters[11].Value = model.goodsValue;
            parameters[12].Value = model.Currency;
            parameters[13].Value = model.customsNo;
            parameters[14].Value = model.inspectionNo;
            parameters[15].Value = model.clearanceNo;
            parameters[16].Value = model.contractNo;
            parameters[17].Value = model.agency;
            parameters[18].Value = model.shipCompany;
            parameters[19].Value = model.remark;
            parameters[20].Value = model.warehouseNo1;
            parameters[21].Value = model.warehouseNo2;
            parameters[22].Value = model.warehouseNo3;
            parameters[23].Value = model.agencyNo;
            parameters[24].Value = model.ladingBillNo;
            parameters[25].Value = model.verificationSheetNo;
            parameters[26].Value = model.containerNo;
            parameters[27].Value = model.headLadingBillNo;
            parameters[28].Value = model.clearanceDate;
            parameters[29].Value = model.transferNo1;
            parameters[30].Value = model.transferNo2;
            parameters[31].Value = model.transferNo3;
            parameters[32].Value = model.filingNo;
            parameters[33].Value = model.invTilte;
            parameters[34].Value = model.inspetionAgancy;
            parameters[35].Value = model.portFee;
            parameters[36].Value = model.Checkfee;
            parameters[37].Value = model.Destination;
            parameters[38].Value = model.PO;
            parameters[39].Value = model.inputEmpNo;
            parameters[40].Value = model.inputDate;
            parameters[41].Value = model.busIDbg;
            parameters[42].Value = model.busIDbj;
            parameters[43].Value = model.busNamebg;
            parameters[44].Value = model.busNamebj;
            parameters[45].Value = model.jobNobg;
            parameters[46].Value = model.jobNobj;
            parameters[47].Value = model.jobEmpNobg;
            parameters[48].Value = model.jobEmpNobj;
            parameters[49].Value = model.infoWKIDbg;
            parameters[50].Value = model.infoWKIDbj;
            parameters[51].Value = model.InfoWKTypeIDbg;
            parameters[52].Value = model.InfoWKTypeIDbj;
            parameters[53].Value = model.BatchNO;
            parameters[54].Value = model.TestItem;
            parameters[55].Value = model.Model;
            parameters[56].Value = model.RegisterUnit;
            parameters[57].Value = model.DangerousGoods;
            parameters[58].Value = model.Transport;
            parameters[59].Value = model.planID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int planID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from T_plan ");
            strSql.Append(" where planID=" + planID + "");
            int rowsAffected = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rowsAffected > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }		/// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string planIDlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from T_plan ");
            strSql.Append(" where planID in (" + planIDlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public CustomsSystem.Model.T_plan GetModel(int planID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1  ");
            strSql.Append(" planID,typeID,inOut,cID,goodsType,tradeType,agencyDate,declaratoryDate,shipName,goodsName,No,grossWeight,goodsValue,Currency,customsNo,inspectionNo,clearanceNo,contractNo,agency,shipCompany,remark,warehouseNo1,warehouseNo2,warehouseNo3,agencyNo,ladingBillNo,verificationSheetNo,containerNo,headLadingBillNo,clearanceDate,transferNo1,transferNo2,transferNo3,filingNo,invTilte,inspetionAgancy,portFee,Checkfee,Destination,PO,inputEmpNo,inputDate,busIDbg,busIDbj,busNamebg,busNamebj,jobNobg,jobNobj,jobEmpNobg,jobEmpNobj,infoWKIDbg,infoWKIDbj,InfoWKTypeIDbg,InfoWKTypeIDbj,BatchNO,TestItem,Model,RegisterUnit,DangerousGoods,Transport from T_plan ");
            strSql.Append(" where planID=" + planID + "");
            CustomsSystem.Model.T_plan model = new CustomsSystem.Model.T_plan();
            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public CustomsSystem.Model.T_plan DataRowToModel(DataRow row)
        {
            CustomsSystem.Model.T_plan model = new CustomsSystem.Model.T_plan();
            if (row != null)
            {
                if (row["planID"] != null && row["planID"].ToString() != "")
                {
                    model.planID = int.Parse(row["planID"].ToString());
                }
                if (row["typeID"] != null && row["typeID"].ToString() != "")
                {
                    model.typeID = int.Parse(row["typeID"].ToString());
                }
                if (row["inOut"] != null && row["inOut"].ToString() != "")
                {
                    model.inOut = int.Parse(row["inOut"].ToString());
                }
                if (row["cID"] != null && row["cID"].ToString() != "")
                {
                    model.cID = int.Parse(row["cID"].ToString());
                }
                if (row["goodsType"] != null && row["goodsType"].ToString() != "")
                {
                    model.goodsType = int.Parse(row["goodsType"].ToString());
                }
                if (row["tradeType"] != null && row["tradeType"].ToString() != "")
                {
                    model.tradeType = int.Parse(row["tradeType"].ToString());
                }
                if (row["agencyDate"] != null && row["agencyDate"].ToString() != "")
                {
                    model.agencyDate = DateTime.Parse(row["agencyDate"].ToString());
                }
                if (row["declaratoryDate"] != null && row["declaratoryDate"].ToString() != "")
                {
                    model.declaratoryDate = DateTime.Parse(row["declaratoryDate"].ToString());
                }
                if (row["shipName"] != null)
                {
                    model.shipName = row["shipName"].ToString();
                }
                if (row["goodsName"] != null)
                {
                    model.goodsName = row["goodsName"].ToString();
                }
                if (row["No"] != null)
                {
                    model.No = row["No"].ToString();
                }
                if (row["grossWeight"] != null && row["grossWeight"].ToString() != "")
                {
                    model.grossWeight = decimal.Parse(row["grossWeight"].ToString());
                }
                if (row["goodsValue"] != null && row["goodsValue"].ToString() != "")
                {
                    model.goodsValue = decimal.Parse(row["goodsValue"].ToString());
                }
                if (row["Currency"] != null)
                {
                    model.Currency = row["Currency"].ToString();
                }
                if (row["customsNo"] != null)
                {
                    model.customsNo = row["customsNo"].ToString();
                }
                if (row["inspectionNo"] != null)
                {
                    model.inspectionNo = row["inspectionNo"].ToString();
                }
                if (row["clearanceNo"] != null)
                {
                    model.clearanceNo = row["clearanceNo"].ToString();
                }
                if (row["contractNo"] != null)
                {
                    model.contractNo = row["contractNo"].ToString();
                }
                if (row["agency"] != null)
                {
                    model.agency = row["agency"].ToString();
                }
                if (row["shipCompany"] != null)
                {
                    model.shipCompany = row["shipCompany"].ToString();
                }
                if (row["remark"] != null)
                {
                    model.remark = row["remark"].ToString();
                }
                if (row["warehouseNo1"] != null)
                {
                    model.warehouseNo1 = row["warehouseNo1"].ToString();
                }
                if (row["warehouseNo2"] != null)
                {
                    model.warehouseNo2 = row["warehouseNo2"].ToString();
                }
                if (row["warehouseNo3"] != null)
                {
                    model.warehouseNo3 = row["warehouseNo3"].ToString();
                }
                if (row["agencyNo"] != null)
                {
                    model.agencyNo = row["agencyNo"].ToString();
                }
                if (row["ladingBillNo"] != null)
                {
                    model.ladingBillNo = row["ladingBillNo"].ToString();
                }
                if (row["verificationSheetNo"] != null)
                {
                    model.verificationSheetNo = row["verificationSheetNo"].ToString();
                }
                if (row["containerNo"] != null)
                {
                    model.containerNo = row["containerNo"].ToString();
                }
                if (row["headLadingBillNo"] != null)
                {
                    model.headLadingBillNo = row["headLadingBillNo"].ToString();
                }
                if (row["clearanceDate"] != null && row["clearanceDate"].ToString() != "")
                {
                    model.clearanceDate = DateTime.Parse(row["clearanceDate"].ToString());
                }
                if (row["transferNo1"] != null)
                {
                    model.transferNo1 = row["transferNo1"].ToString();
                }
                if (row["transferNo2"] != null)
                {
                    model.transferNo2 = row["transferNo2"].ToString();
                }
                if (row["transferNo3"] != null)
                {
                    model.transferNo3 = row["transferNo3"].ToString();
                }
                if (row["filingNo"] != null)
                {
                    model.filingNo = row["filingNo"].ToString();
                }
                if (row["invTilte"] != null)
                {
                    model.invTilte = row["invTilte"].ToString();
                }
                if (row["inspetionAgancy"] != null)
                {
                    model.inspetionAgancy = row["inspetionAgancy"].ToString();
                }
                if (row["portFee"] != null && row["portFee"].ToString() != "")
                {
                    model.portFee = decimal.Parse(row["portFee"].ToString());
                }
                if (row["Checkfee"] != null && row["Checkfee"].ToString() != "")
                {
                    model.Checkfee = decimal.Parse(row["Checkfee"].ToString());
                }
                if (row["Destination"] != null)
                {
                    model.Destination = row["Destination"].ToString();
                }
                if (row["PO"] != null)
                {
                    model.PO = row["PO"].ToString();
                }
                if (row["inputEmpNo"] != null)
                {
                    model.inputEmpNo = row["inputEmpNo"].ToString();
                }
                if (row["inputDate"] != null && row["inputDate"].ToString() != "")
                {
                    model.inputDate = DateTime.Parse(row["inputDate"].ToString());
                }
                if (row["busIDbg"] != null && row["busIDbg"].ToString() != "")
                {
                    model.busIDbg = int.Parse(row["busIDbg"].ToString());
                }
                if (row["busIDbj"] != null && row["busIDbj"].ToString() != "")
                {
                    model.busIDbj = int.Parse(row["busIDbj"].ToString());
                }
                if (row["busNamebg"] != null)
                {
                    model.busNamebg = row["busNamebg"].ToString();
                }
                if (row["busNamebj"] != null)
                {
                    model.busNamebj = row["busNamebj"].ToString();
                }
                if (row["jobNobg"] != null)
                {
                    model.jobNobg = row["jobNobg"].ToString();
                }
                if (row["jobNobj"] != null)
                {
                    model.jobNobj = row["jobNobj"].ToString();
                }
                if (row["jobEmpNobg"] != null)
                {
                    model.jobEmpNobg = row["jobEmpNobg"].ToString();
                }
                if (row["jobEmpNobj"] != null)
                {
                    model.jobEmpNobj = row["jobEmpNobj"].ToString();
                }
                if (row["infoWKIDbg"] != null && row["infoWKIDbg"].ToString() != "")
                {
                    model.infoWKIDbg = int.Parse(row["infoWKIDbg"].ToString());
                }
                if (row["infoWKIDbj"] != null && row["infoWKIDbj"].ToString() != "")
                {
                    model.infoWKIDbj = int.Parse(row["infoWKIDbj"].ToString());
                }
                if (row["InfoWKTypeIDbg"] != null && row["InfoWKTypeIDbg"].ToString() != "")
                {
                    model.InfoWKTypeIDbg = int.Parse(row["InfoWKTypeIDbg"].ToString());
                }
                if (row["InfoWKTypeIDbj"] != null && row["InfoWKTypeIDbj"].ToString() != "")
                {
                    model.InfoWKTypeIDbj = int.Parse(row["InfoWKTypeIDbj"].ToString());
                }
                if (row["BatchNO"] != null)
                {
                    model.BatchNO = row["BatchNO"].ToString();
                }
                if (row["TestItem"] != null)
                {
                    model.TestItem = row["TestItem"].ToString();
                }
                if (row["Model"] != null)
                {
                    model.Model = row["Model"].ToString();
                }
                if (row["RegisterUnit"] != null)
                {
                    model.RegisterUnit = row["RegisterUnit"].ToString();
                }
                if (row["DangerousGoods"] != null && row["DangerousGoods"].ToString() != "")
                {
                    if ((row["DangerousGoods"].ToString() == "1") || (row["DangerousGoods"].ToString().ToLower() == "true"))
                    {
                        model.DangerousGoods = true;
                    }
                    else
                    {
                        model.DangerousGoods = false;
                    }
                }
                if (row["Transport"] != null)
                {
                    model.Transport = row["Transport"].ToString();
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select planID,typeID,inOut,cID,goodsType,tradeType,agencyDate,declaratoryDate,shipName,goodsName,No,grossWeight,goodsValue,Currency,customsNo,inspectionNo,clearanceNo,contractNo,agency,shipCompany,remark,warehouseNo1,warehouseNo2,warehouseNo3,agencyNo,ladingBillNo,verificationSheetNo,containerNo,headLadingBillNo,clearanceDate,transferNo1,transferNo2,transferNo3,filingNo,invTilte,inspetionAgancy,portFee,Checkfee,Destination,PO,inputEmpNo,inputDate,busIDbg,busIDbj,busNamebg,busNamebj,jobNobg,jobNobj,jobEmpNobg,jobEmpNobj,infoWKIDbg,infoWKIDbj,InfoWKTypeIDbg,InfoWKTypeIDbj,BatchNO,TestItem,Model,RegisterUnit,DangerousGoods,Transport ");
            strSql.Append(" FROM T_plan ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" planID,typeID,inOut,cID,goodsType,tradeType,agencyDate,declaratoryDate,shipName,goodsName,No,grossWeight,goodsValue,Currency,customsNo,inspectionNo,clearanceNo,contractNo,agency,shipCompany,remark,warehouseNo1,warehouseNo2,warehouseNo3,agencyNo,ladingBillNo,verificationSheetNo,containerNo,headLadingBillNo,clearanceDate,transferNo1,transferNo2,transferNo3,filingNo,invTilte,inspetionAgancy,portFee,Checkfee,Destination,PO,inputEmpNo,inputDate,busIDbg,busIDbj,busNamebg,busNamebj,jobNobg,jobNobj,jobEmpNobg,jobEmpNobj,infoWKIDbg,infoWKIDbj,InfoWKTypeIDbg,InfoWKTypeIDbj,BatchNO,TestItem,Model,RegisterUnit,DangerousGoods,Transport ");
            strSql.Append(" FROM T_plan ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM T_plan ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.planID desc");
            }
            strSql.Append(")AS Row, T.*  from T_plan T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取gv视图
        /// </summary>
        public DataSet GetView(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select a.planID ,typeID=case a.typeID when 1 then '单独报关' WHEN 2 then '单独报检' WHEN 3 then '报关报检' when 4 then '加签' when 5 then '危险品' when 6 then '其他' end,b.codeName as goodsType,c.customerName as cID , a.tradeType ,c2.codename as inOut,a.goodsName,No,a.grossWeight,a.goodsValue,a.remark,a.Checkfee,a.Destination,a.PO,a.NO ");
            strSql.Append(" from T_plan a left join Info_code b on(codeType='goodType'and codeID=a.goodsType)left join Cu_Customer c on(c.ID=a.cID) left join Info_code c2 on(a.inOut=c2.codeID and c2.codeType='inoutType')  ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        /*
        */

        #endregion  Method
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

